//
//  MyEvaluateMangerViewController.m
//  shopping
//
//  Created by 徐双 on 2017/9/15.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "MyEvaluateMangerViewController.h"
#import "evaluteWithoutViewCell.h"
#import "MyComentWithImageViewCell.h"
#import "MyCommentCollectionViewCell.h"
@interface MyEvaluateMangerViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView * tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) NSMutableArray *arrOfPic;
@end

@implementation MyEvaluateMangerViewController
- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    [self creationData];
    
}
-(void)viewDidLoad{

    [super viewDidLoad];
    
    //初始化tableView
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64 - 160 - 40);
    
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //self.tableView.estimatedRowHeight = 400;
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线

    [self.view addSubview:self.tableView];
    self.view.backgroundColor = [UIColor colorWithRed:245 / 255.0f green:245 / 255.0f blue:245 / 255.0f alpha:1];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"evaluteWithoutViewCell" bundle:nil] forCellReuseIdentifier:@"evaluteWithoutViewCell"];

     [self.tableView registerNib:[UINib nibWithNibName:@"MyComentWithImageViewCell" bundle:nil] forCellReuseIdentifier:@"MyComentWithImageViewCell"];

}
- (void)creationData{
    
    _dataArr = [NSMutableArray array];
    _arrOfPic = [NSMutableArray array];
    
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    hud.tag = 500;
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    
 //   [productParams setValue:@"3328d8ca958957123d086c4ff33c44bd3ecc" forKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:@"1" forKey:@"type"];
    
    [[MNetworkHandler sharedInstance]conURL:adminLxlpersonAppraise networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"code"]intValue]==100) {
            
            self.dataArr = [returnData objectForKey:@"data1"];
            
            
            NSLog(@"~~~~~~~~~~~~~~~~~~~~~%@", self.dataArr);
            
            [self.tableView reloadData];
            [hud removeFromSuperview];
            
            
        }
        
        else {
            
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            [hud removeFromSuperview];
            
            
        }
        
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        [hud removeFromSuperview];
        
    }];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.dataArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSMutableDictionary *dicOfPic = self.dataArr[indexPath.row];
    self.arrOfPic = [dicOfPic objectForKey:@"picpath"];
    
    if (self.arrOfPic.count > 0 && self.arrOfPic.count <= 3) {
        return 185 + 105;
        
    }else if (self.arrOfPic.count > 3 && self.arrOfPic.count <= 6){
        
        return 185 + 210;
        
    }else if (self.arrOfPic.count > 6 && self.arrOfPic.count <= 9) {
        
        return 185 + 315;
        
    }else {
    
      return 131;
    }

    
    
    

}

-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSMutableDictionary *dicOfPic = self.dataArr[indexPath.row];
    self.arrOfPic = [dicOfPic objectForKey:@"picpath"];
    if (self.arrOfPic.count == 0) {
        
        evaluteWithoutViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"evaluteWithoutViewCell"];
        
        cell.selectionStyle = UITableViewCellAccessoryNone;
        
        cell.creationTime.text = [dicOfPic objectForKey:@"createTime"];
        cell.ping.text = [dicOfPic objectForKey:@"ping"];
        cell.goodname.text = [dicOfPic objectForKey:@"shopname"];
        
        if ([[dicOfPic objectForKey:@"content"] length] == 0) {
            cell.content.text = @"评论方未及时作出评价,系统默认好评";
        }else {
            
            cell.content.text = [dicOfPic objectForKey:@"content"];
        }
        
        
        NSString *urlN=manage(AP_Img, [dicOfPic objectForKey:@"goodsImg"]);
        
        [cell.goodsImg sd_setImageWithURL:[NSURL URLWithString:urlN] placeholderImage:[UIImage imageNamed:@""]];
        
        
        
        return cell;
    }else {
    
        MyComentWithImageViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MyComentWithImageViewCell"];
        
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        
        NSMutableDictionary *dicOfPic = self.dataArr[indexPath.row];
        NSMutableArray *arrOfPic = [dicOfPic objectForKey:@"picpath"];
        cell.arrOfPic = arrOfPic;
        
        cell.createTime.text = [dicOfPic objectForKey:@"createTime"];
        cell.ping.text = [dicOfPic objectForKey:@"ping"];
        cell.goodname.text = [dicOfPic objectForKey:@"shopname"];
        
        if ([[dicOfPic objectForKey:@"content"] length] == 0) {
            cell.content.text = @"评论方未及时作出评价,系统默认好评";
        }else {
            
            cell.content.text = [dicOfPic objectForKey:@"content"];
        }
        
        
        NSString *urlN=manage(AP_Img, [dicOfPic objectForKey:@"goodsImg"]);
        
        [cell.goodsImg sd_setImageWithURL:[NSURL URLWithString:urlN] placeholderImage:[UIImage imageNamed:@""]];
        
        
        return cell;

        
    }
    
    
    

}


@end
